<template >
  <div style="width: 100vw;height: 100vh;display: flex;justify-content: center;align-items: center">
    <el-form ref="loginForm" :rules="rules" :model="loginForm" label-width="80px">
      <el-form-item label="用户名" prop="email">
        <el-input v-model="loginForm.email"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="loginForm.password" show-password></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="checklogin()">登录</el-button>
        <!-- <el-button @click="resetForm('loginForm')">重置</el-button> -->
        <!-- <el-row>
          <el-col :span="12">
            <el-link type="primary">注册</el-link>
          </el-col>
          <el-col :span="12" style="text-align:right">
            <el-link type="primary">忘记密码</el-link>
          </el-col>
        </el-row> -->
      </el-form-item>
    </el-form>
  </div>
</template>
<style>
#app {
  background-image: url('../../assets/images/719.jpg');
  background-size: 100% 100%;
}
</style>
<script>
import { setToken } from "@/utils/common";
import { loginApi } from "@/api/loginManage/login.js";
// import { login } from "@/api/user/user";
export default {
  data() {
    return {
      // imgSrc:require('../../assets/images/719.jpg'),
      loginForm: {
        email: "",
        password: ""
      },
      rules: {
        email: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    checklogin() {
      if (this.loginForm.email == '' || this.loginForm.password == '') {
        return;
      }
      loginApi({
        "email": this.loginForm.email,
        "password": this.loginForm.password
      })
        .then(resp => {
          console.log(this.loginForm.email + this.loginForm.password);
          console.log(resp);
          if (resp.id != null) {
            // this.$setSessionStorage('user', this.user);
            window.sessionStorage.setItem('loginForm', JSON.stringify(resp));
            console.log(sessionStorage);
            this.$router.push('/home')
          }
          else {
            console.log("error");
            return;
          }
        })
    },
    // resetForm(loginForm) {
    //   this.$refs[loginForm].resetFields();
    // }
  },
  mounted: function () { }
};
</script>